<?php

namespace app\admin\controller;

use app\common\model\Admin;
use app\common\model\Rule;
use think\Controller;
use think\Request;
use luck\auth\Auth;

class Index extends Common
{
    public function index(){
        $uid=session(config('auth.ADMIN_AUTH_KEY'));
        //当前登录用户
        $admin=new Admin();
        $userInfo=$admin->where('id',$uid)->find();
        $this->assign('admin',$userInfo);

        //顶级菜单
        $cate=Rule::where(['status'=>1,'showed'=>1,'pid'=>0])->order('id','asc')->select();
        $cates=[];
        if(in_array($uid,config('auth.ADMINISTRATOR'))){
            $cates=$cate;
        }else{
            $user=Admin::field('password',true)->find($uid);
            $group=$user->authGroup;
            $rid='';
            foreach($group as $g){
                $rid.=$g['rules'].',';
            }
            $rids=array_filter(array_unique(explode(',',$rid)));

            foreach($cate as $v){
                if(in_array($v['id'],$rids)){
                    $cates[]=$v;
                }
            }
        }
        $this->assign('topmenu',$cates);
        return view();
    }

    //首页控制台信息
    public function info(){
        print_r(date('Y-m-d H:i:s',THINK_START_TIME));
        echo '<br>';
        echo THINK_START_MEM;
        echo '<br>';
        echo ENV_PREFIX ;
        echo '<br>';
        echo IS_CLI;
        echo '<br>';
        echo IS_WIN;
        echo '<br>';
        echo THINK_VERSION;
        echo '<br>';
        print_r($this->request->dispatch());
        print_r(session(''));
        return view();
    }
}
